#!/usr/bin/env python
#
# Copyright (C) 2011 Clement Lorteau <clem@lorteau.fr>	
#		
# This file is part of QuickScreenShots.		
# 	
# This program is free software; you can redistribute it and/or modify	
# it under the terms of the GNU General Public License as published by		
# the Free Software Foundation; version 3.	
# 	
# This program is distributed in the hope that it will be useful,		
# but WITHOUT ANY WARRANTY; without even the implied warranty of		
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the		
# GNU General Public License for more details.		
# 		
# You should have received a copy of the GNU General Public License		
# along with this program; if not, write to the Free Software		
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

import wx
from wx.lib.buttons import ThemedGenBitmapTextButton as bbutton
from __init__ import resources

class CheckYesNoDialog(wx.Dialog):
    def __init__(self, title, message, checktext, *args, **kwds):
        """If checktext = empty string, no checkbox is shown"""
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.title = title
        okbmp = wx.Bitmap("%s/ok_16.png" % resources, wx.BITMAP_TYPE_PNG)
        cancelbmp = wx.Bitmap("%s/cancel_16.png" % resources, wx.BITMAP_TYPE_PNG)
        self.bitmap_icon = wx.StaticBitmap(self, -1, wx.Bitmap("%s/update_48.png" % resources, wx.BITMAP_TYPE_PNG))
        self.label_1 = wx.StaticText(self, -1, message)
        if checktext != '':
            self.checkbox_1 = wx.CheckBox(self, -1, checktext)
        else:
            self.checkbox_1 = None
        self.yesbutton = bbutton(self, wx.ID_OK, okbmp, '  Yes')
        self.nobutton = bbutton(self, wx.ID_CANCEL, cancelbmp, '  No')

        self.__set_properties()
        self.__do_layout()
        
    def __set_properties(self):
        self.SetTitle(self.title)

    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_1 = wx.GridSizer(1, 2, 0, 10)
        grid_sizer_1.Add(self.yesbutton, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL)
        grid_sizer_1.Add(self.nobutton, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_2.Add(self.bitmap_icon, 0, wx.ALL, 10)
        sizer_3.Add(self.label_1, 0, wx.ALL, 10)
        if self.checkbox_1:
            sizer_3.Add(self.checkbox_1, 0, wx.ALL, 10)
        sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        sizer_1.Add(grid_sizer_1, 0, wx.EXPAND|wx.ALL, 5)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        
    def GetChecked(self):
        """Return True is the checkbox is checked, False if not.
           Return None if there's no checkbox"""
        if self.checkbox_1:
            return self.checkbox_1.GetValue()
        else:
            return None

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    title = "QuickScreenShots: new update available"
    message = "A new update of QuickScreenShots is available.\nDo you want to visit the download page?"
    check_text = "Don't ask me again"
    dialog_1 = CheckYesNoDialog(title, message, check_text, None,-1, "")
    ret = dialog_1.ShowModal()
    if ret == wx.ID_OK:
        print "Yes"
        print "Checked:", dialog_1.GetChecked()
    if ret == wx.ID_CANCEL:
        print "No"